define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionreportmonthtwop/index' + location.search,
                    add_url: 'feditionreportmonthtwop/add',
                    edit_url: 'feditionreportmonthtwop/edit',
                    del_url: 'feditionreportmonthtwop/del',
                    multi_url: 'feditionreportmonthtwop/multi',
                    import_url: 'feditionreportmonthtwop/import',
                    table: 'fedition_reportmonth',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'timedate',
                search:false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'timedate', title: __('Timedate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM"},
                        {field: 'admin_id', title: __('店铺管理者'),visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
                        {field: 'admin_name', title: __('店铺管理者'), operate: false},
                        {field: 'material', title: __('采购成本(美金)'), operate:'BETWEEN',sortable:true},
                        {field: 'freightmj', title: __('物流成本(美金)'), operate:'BETWEEN',sortable:true},
                        {field: 'advertisingz', title: __('广告成本'), operate:'BETWEEN',sortable:true},
                        // {field: 'status_freight',title: __('物流成本确认'),formatter: Table.api.formatter.toggle,yes: 'normal',no: 'hidden'},
                        // {field: 'status_material',title: __('采购成本确认'),formatter: Table.api.formatter.toggle,yes: 'normal',no: 'hidden'},
                        {field: 'zcost', title: __('Zcost'), operate:'BETWEEN',sortable:true},
                        {field: 'gross_profit', title: __('Gross_profit'), operate:'BETWEEN',sortable:true},
                        {field: 'salesz', title: __('总销售额'), operate:'BETWEEN',sortable:true},
                        {field: 'salesz_discount', title: __('总销售额($)(95%)'), operate:'BETWEEN',sortable:true},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('店铺管理'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('店铺列表'),
                                    title: __('店铺列表'),
                                    extend: 'data-area=\'["90%","90%"]\'',
                                    classname: 'btn btn-sm btn-warning btn-dialog',
                                    icon: 'fa fa-magic',
                                    url: 'feditionreportmonthp/index/?admin_id={admin_id}&timedate={timedate}'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});